package com.jxb.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.jxb.moniDubbo.OrderStream;
import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;

import com.jxb.moniDubbo.User;
import com.jxb.moniDubbo.UserService;

@DubboService
 @Path("/user")
 @Produces
public class UserServiceImpl implements UserService {

     @GET
     @Path("/{uid}")
     @Produces(MediaType.APPLICATION_JSON)
    @Override
     public User getUser(@PathParam("uid") String uid) {
//    public User getUser(String uid) {
        User user = new User();
        user.setUid(uid);
        user.setUsername("jbbbbbbbb");
        return user;
    }

    @Override
    public void sayHelloServerStream(String name, OrderStream stream1) {
        stream1.onNext(name + "hello");
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        stream1.onNext(name + " world");
        stream1.onCompleted();
    }

    //实现双端流
    @Override
    public OrderStream sayHelloStream(OrderStream response) {
        OrderStream orderStream = new OrderStream();
        orderStream.onNext("123");
        orderStream.onCompleted();
        return orderStream ;
    }
}